package com.asohofrucol.dto.util;

import com.asohofrucol.dto.AssociativityRegisterDTO;
import com.asohofrucol.model.Associativity;
import com.asohofrucol.model.ComboValue;
import com.asohofrucol.model.Ruat;

public class AssociativityHelperDto {

	public static AssociativityRegisterDTO convertToRegisterDTO(
			Associativity associativity) {

		AssociativityRegisterDTO associativityDTO = new AssociativityRegisterDTO();

		associativityDTO.setAssociationClass((associativity
				.getComboValueAssociationClass() != null) ? associativity
				.getComboValueAssociationClass().getId() : null);

		associativityDTO.setAssociationClassDesc((associativity
				.getComboValueAssociationClass() != null) ? associativity
				.getComboValueAssociationClass().getDescription() : null);

		associativityDTO
				.setBenefit((associativity.getComboValueBenefit() != null) ? associativity
						.getComboValueBenefit().getId() : null);

		associativityDTO
				.setBenefitDesc((associativity.getComboValueBenefit() != null) ? associativity
						.getComboValueBenefit().getDescription() : null);

		associativityDTO.setId(associativity.getId());
		associativityDTO.setMeetingFrequency((associativity
				.getComboValueMeetingFrequency() != null) ? associativity
				.getComboValueMeetingFrequency().getId() : null);

		associativityDTO.setMeetingFrequencyDesc((associativity
				.getComboValueMeetingFrequency() != null) ? associativity
				.getComboValueMeetingFrequency().getDescription() : null);

		associativityDTO.setModifiedDate(associativity.getModifiedDate());
		associativityDTO.setModifierUser(associativity.getModifierUser());
		associativityDTO.setOrganizationName(associativity
				.getOrganizationName());
		associativityDTO.setRuatId(associativity.getRuat().getId());
		associativityDTO.setStatus(associativity.getStatus());
		associativityDTO.setWorkInOrganization((associativity
				.getComboValueWorkInOrganization() != null) ? associativity
				.getComboValueWorkInOrganization().getId() : null);

		associativityDTO.setWorkInOrganizationDesc((associativity
				.getComboValueWorkInOrganization() != null) ? associativity
				.getComboValueWorkInOrganization().getDescription() : null);
		return associativityDTO;
	}

	public static Associativity converRegisterToEntity(
			AssociativityRegisterDTO associativityRegisterDTO) {

		Associativity entity = new Associativity();

		entity.setComboValueAssociationClass(new ComboValue(
				associativityRegisterDTO.getAssociationClass()));
		entity.setComboValueBenefit(new ComboValue(associativityRegisterDTO
				.getBenefit()));
		entity.setComboValueMeetingFrequency(new ComboValue(
				associativityRegisterDTO.getMeetingFrequency()));
		entity.setComboValueWorkInOrganization(new ComboValue(
				associativityRegisterDTO.getWorkInOrganization()));
		entity.setId(associativityRegisterDTO.getId());
		entity.setModifiedDate(associativityRegisterDTO.getModifiedDate());
		entity.setModifierUser(associativityRegisterDTO.getModifierUser());
		entity.setOrganizationName(associativityRegisterDTO
				.getOrganizationName());
		entity.setRuat(new Ruat(associativityRegisterDTO.getRuatId()));
		entity.setStatus(associativityRegisterDTO.getStatus());

		return entity;
	}

}
